<template lang="">
  <div v-if="row">
    <div class="_flex _p10 _flex-start">
      <el-input
        v-model="row.title"
        placeholder="请输入标题"
        style="width: 300px; margin-right: 15px"
      ></el-input>
      <el-button type="primary" @click="save()">同步</el-button>
      <el-button type="danger" @click="remove()">删除</el-button>
    </div>
    <div class="_p10 _p-t-0">
      <com-vditor-vue v-model:content="row.content" />
    </div>
  </div>
</template>
<script>
import ComVditorVue from "@/components/com-vditor/com-vditor.vue";
import ToolAction from "@/tool/http/tool-action.js";

const accountContentAction = ToolAction.init("account_content");

export default {
  components: { ComVditorVue },
  props: {
    id: {
      type: String,
      required: false,
    },
    winParam: {
      type: Object,
      required: false,
    },
  },
  data() {
    return {
      row: undefined,
      rowId: this.id || (this.winParam || {}).id,
    };
  },
  mounted() {
    if (this.rowId) {
      accountContentAction.view({ id: this.rowId }).then((res) => {
        this.row = res;
      });
    } else {
      this.row = this.winParam || {};
    }
  },
  methods: {
    save() {
      accountContentAction.sync(this.row).then((res) => {
        this.row.id = res.id;
        this.$element.msg();
      });
    },
    remove() {
      accountContentAction.remove({ id: this.rowId }).then((res) => {
        this.$element.msg();
      });
    },
  },
};
</script>
<style lang=""></style>
